package com.lhc.nacosprovider.task;

import io.github.biezhi.ome.OhMyEmail;
import io.github.biezhi.ome.SendMailException;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import javax.annotation.PostConstruct;

import static io.github.biezhi.ome.OhMyEmail.SMTP_QQ;

/**
 * @author liuchaoqun
 * @date 2022/6/20
 * @Description 定时任务
 */
@EnableScheduling
@Configuration
public class EmailTask {

    private static final String TO_EMAIL = "274839337@qq.com";

    @PostConstruct
    public void init() {
        // 配置，一次即可 your@password不是指QQ邮箱的密码，是指QQ邮箱的授权码
        OhMyEmail.config(SMTP_QQ(false), "1069320627@qq.com", "ptwogmxffccqbcae");
    }

//    @Scheduled(cron = "0/5 * * * * ? ")
    public void EmailTask() throws SendMailException {

        OhMyEmail.subject("这是一封测试TEXT邮件")
                .from("小姐姐的邮箱")
                .to(TO_EMAIL)
                .text("信件内容")
                .send();
        System.out.println("以及发送一条邮件" + System.currentTimeMillis());
    }

}
